package cn.wellwan.express.impl;

import cn.wellwan.commons.WellwanBusinessException;
import cn.wellwan.express.*;
import cn.wellwan.utils.HttpClient;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C),微动天下
 * FileName: KDNiaoServiceImpl
 * Author:   maokai
 * Date:     2018/12/19 13:46
 * Description: 快递鸟接口实现业务
 */
@Service
@Slf4j
public class KDNiaoServiceImpl implements KDNiaoService {

    @Autowired
    private SpringHttpClient springHttpClient;

    @Autowired
    private Config config;

    /***
     * 轨迹查询接口
     * @param expCode 快递公司编码
     * @param expNo 快递单号
     */
    @Override
    public void shipTraces(String expCode, String expNo) throws Exception {
        if (StringUtils.isBlank(expCode)) {
            throw new WellwanBusinessException("快递公司编码不能为空");
        }
        if (StringUtils.isBlank(expCode)) {
            throw new WellwanBusinessException("快递单号不能为空");
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("OrderCode","");
        jsonObject.put("ShipperCode",expCode);
        jsonObject.put("LogisticCode",expNo);
        String requestData = JSONObject.toJSONString(jsonObject);
        Map<String, String> params = new HashMap<>();
        params.put("RequestData", KDNiaoEncrypt.urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", config.getId());
        params.put("RequestType", "1002");
        String dataSign = KDNiaoEncrypt.encrypt(requestData, config.getKey(), "UTF-8");
        params.put("DataSign", KDNiaoEncrypt.urlEncoder(dataSign, "UTF-8"));
        params.put("DataType", "2");
        String url = config.getURL(Config.InterfaceURL.ORDER_TRACES);
        KDNiaoHttp kdNiaoHttp = new KDNiaoHttp();
        String s = kdNiaoHttp.sendPost(url, params);

    }

    @Override
    public List<Shipper> shipperList() {


        return null;
    }
}
